package com.explorex.infra.puma.gateway.netty.common.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public enum EnumBiz {
    PING(0, "ping"),
    IM(1, "im"),
    PUSH(2, "push"),
    RENO(3, "reno"),
    ROOM(4, "room"),
    IMPAAS(10, "impaas"),
    AUTH(256, "auth"),
    LOGOUT(512, "logout"),
    UNDEFINED(99, "undefined");

    private final int bizId;
    private final String bizName;
    private static final Map<Integer, EnumBiz> BIZ_MAP = getBizMap();
    private static final Map<String, EnumBiz> STRING_BIZ_MAP = getStringBizMap();

    private static Map<String, EnumBiz> getStringBizMap() {
        return (Map) Arrays.stream(values()).collect(Collectors.toMap(EnumBiz::getBizName, (e) -> {
            return e;
        }));
    }

    private static Map<Integer, EnumBiz> getBizMap() {
        return (Map)Arrays.stream(values()).collect(Collectors.toMap(EnumBiz::getBizId, (e) -> {
            return e;
        }));
    }

    public static int getBizId(String bizName) {
        EnumBiz enumBiz = (EnumBiz)STRING_BIZ_MAP.get(bizName);
        return enumBiz != null ? enumBiz.getBizId() : UNDEFINED.getBizId();
    }

    public static String getBizNameById(Integer bizId) {
        EnumBiz enumBiz = (EnumBiz)BIZ_MAP.get(bizId);
        return enumBiz != null ? enumBiz.getBizName() : UNDEFINED.getBizName();
    }

    private EnumBiz(int bizId, String bizName) {
        this.bizId = bizId;
        this.bizName = bizName;
    }

    public static EnumBiz findById(int bizId) {
        EnumBiz[] var1 = values();
        int var2 = var1.length;

        for(int var3 = 0; var3 < var2; ++var3) {
            EnumBiz value = var1[var3];
            if (value.bizId == bizId) {
                return value;
            }
        }

        return UNDEFINED;
    }

    public int getBizId() {
        return this.bizId;
    }

    public String getBizName() {
        return this.bizName;
    }

    public String toString() {
        return "EnumBiz{bizId=" + this.bizId + ", bizName='" + this.bizName + '\'' + '}';
    }
}